package com.wuming.caiwu.service.impl;

import com.wuming.caiwu.core.BusinessException;
import com.wuming.caiwu.dao.SysUserRoleMapper;
import com.wuming.caiwu.model.SysUserRole;
import com.wuming.caiwu.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class SysUserRoleServiceImpl extends BaseServiceImpl implements SysUserRoleService {

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Override
    public void saveSysUserRole(SysUserRole member) throws BusinessException {
        sysUserRoleMapper.insert(member);
    }

    @Override
    public void modifySysUserRole(SysUserRole member) throws BusinessException {
        sysUserRoleMapper.updateByPrimaryKey(member);
    }

    @Override
    public SysUserRole getSysUserRoleById(Long id) throws BusinessException {
        return sysUserRoleMapper.selectByPrimaryKey(id);
    }

    @Override
    public void removeSysUserRoleById(Long id) throws BusinessException {
        sysUserRoleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public SysUserRole getUserRoleByUserId(Long adminId) throws BusinessException {
        Map<String,Object> params = new HashMap<>();
        if(null != adminId){
            params.put("adminId",adminId);
        }
        return sysUserRoleMapper.selectByParams(params);
    }
}
